package com.tk.exam.dao;

import com.github.pagehelper.PageInfo;
import com.tk.exam.domain.TkQuestions;
import com.tk.exam.domain.TkQuestionsExample;
import com.tk.exam.mapper.TkQuestionsMapper;
import com.tk.exam.vo.question.TkQuestionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class TkQuestionDao {

    @Autowired
    private TkQuestionsMapper tkQuestionMapper;

    public PageInfo<TkQuestionVo> selectQuestionWithPage(String category,String type) {
        Map map = new HashMap();
        map.put("category", category);
        map.put("type", type);
        return new PageInfo<TkQuestionVo>(this.tkQuestionMapper.searchTkQuesList(map));
    }
    @Transactional
    public TkQuestions save(TkQuestions tkQuestions) {
        Integer id;
        if (tkQuestions.getId() != null) {
            id = this.tkQuestionMapper.updateByPrimaryKeyWithBLOBs(tkQuestions);
        } else {
            id = this.tkQuestionMapper.insert(tkQuestions);
        }
        return this.tkQuestionMapper.selectByPrimaryKey(id);
    }
    public TkQuestions findById(String id){
        return this.tkQuestionMapper.selectByPrimaryKey(Integer.valueOf(id));
    }

    public List<TkQuestions> findByIds(List<Integer> ids){
        TkQuestionsExample example = new TkQuestionsExample();
        example.or().andIdIn(ids);
        return this.tkQuestionMapper.selectByExample(example);
    }
    @Transactional
    public int deleteByIds(List<Integer> ids){
        TkQuestionsExample example = new TkQuestionsExample();
        example.or().andIdIn(ids);
        return this.tkQuestionMapper.deleteByExample(example);
    }




}
